package homework22;

import java.util.ArrayList;
@SuppressWarnings({"all"})
public class Composite extends Component {
    private ArrayList<Component> arrayList = new ArrayList<>();
    private String name;

    public Composite(String name) {
        this.name = name;
    }

    @Override
    public void operation() {
        System.out.println("对文件" + name + "杀毒...");
        for (Object o :arrayList) {
            ((Component) o).operation();
        }
    }

    @Override
    public void remove(Component component) {
        arrayList.remove(component);
    }

    @Override
    public void add(Component component) {
        arrayList.add(component);
    }

    @Override
    public Component getChild(int i) {
        return (Component) arrayList.get(i);
    }
}
